<?php

App::uses('CrudController', 'Controller');
App::uses('Area', 'Model');
App::uses('User', 'Model');

class UserAreasController extends CrudController
{
    public $_model = 'UserArea';

    public function admin($userId) {
        $this->request->allowMethod('get');
        $this->loadModel('Area');
        $this->loadModel('User');
        $areas = $this->Area->getEnabledWithMoe();
        $description = $this->getDescription($userId);
        $appBosch = new stdClass();
//        $appBosch->areas = $areas;
        $appBosch->userId = $userId;
        $appBosch->areas = $areas;
        $this->set('appBoschAreas', $appBosch);
        $this->set('title', __('Asignar área'));
        $this->set('description', $description);
        $this->layout = 'empty';
    }
    
    private function getDescription($userId) {
        $this->User->id = $userId;
        $user = $this->User->read();
        return mb_strtoupper($user['User']['full_name']);
    }

    protected function getRecords($param) {
        $m = $this->_model;
        $records = $this->$m->getByUser($param);
        return $records;
    }

    protected function c($model) {
        $m = $this->_model;
        return array(
            'user_id' => $model->user_id,
            'area_id' => $model->area_id,
        );
    }

    protected function u($model) {
        return array(
            'area_id' => $model->area_id,
        );
    }

}
